﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;

namespace NASA.BeAMartian.Views.Learn
{
    public partial class QuestionPage : PhoneApplicationPage
    {
        public QuestionPage()
        {
            InitializeComponent();

            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
            FrameworkElement _root = Application.Current.RootVisual as FrameworkElement;
            ClientState clientState = (ClientState)_root.DataContext;
            if (clientState == null) { clientState = new ClientState(); }
            tbQuestionBody.DataContext = clientState.CurrentQuestion;
            lbResponses.ItemsSource = clientState.CurrentQuestion.Responses;
            tbQuestionPosterPoints.Text = clientState.CurrentQuestion.NuggetOriginator.UserReputationString;
            tbQuestionPosterUsername.Text = clientState.CurrentQuestion.NuggetOriginator.DisplayName;
            tbPoints.Text = (clientState.CurrentQuestion.Votes.UpVotes + clientState.CurrentQuestion.Votes.DownVotes).ToString();
            this.imgAvatar.Source = new BitmapImage(new Uri(clientState.CurrentQuestion.NuggetOriginator.Avatar));
            //this.btnVoteDown.VotePercentage = Convert.ToInt16(clientState.CurrentQuestion.Votes.DownPercentage);
            //this.btnVoteUp.VotePercentage = Convert.ToInt16(clientState.CurrentQuestion.Votes.UpPercentage);

            tbPageTitle.Text = String.Format("TOPIC: {0}", clientState.CurrentQuestion.CategoryName.ToUpper());
        }

        // Handle navigating back to content in the two frames
        private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // Cancel default navigation
            e.Cancel = true;

        }

        private void btnPostAResponse_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/AskQuestionPage.xaml", UriKind.Relative));
        }
    }
}